package com.bosicen.crm.service.sysmanage;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;

import com.bosicen.crm.dao.entity.Product;
import com.bosicen.crm.dao.sysmanage.ProductDao;
import com.bosicen.crm.tools.Page;

import org.springframework.transaction.annotation.Transactional;
/**
 * 商品
 * @author tigerlei
 *
 */
@Service("productService")
public class ProductServiceImpl {
	@Autowired
	private ProductDao productDao;

	// @Transactional(readOnly = false,propagation=Propagation.REQUIRED,
	// rollbackFor=Exception.class)

	/****
	 * 查询列表
	 * 
	 * @param companyid
	 * @return
	 */
	public List<Product> findProductList(Product product) {
		List<Product> list = null;
		try {
			list = this.productDao.findProductList(product);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return list;
	}

	/***
	 * 新增/修改
	 * 
	 * @param p
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public boolean saveOrUpdateProduct(Product p) {
		try {
			 this.productDao.saveOrUpdate(p);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}

	/****
	 * 按ID查询
	 * 
	 * @param companyid
	 * @return
	 */
	public Product findProductById(int id) {
		Product product = null;
		try {
			product = this.productDao.findProductById(id);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return product;
	}

	/****
	 * 删除 
	 * 
	 * @param p
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public boolean delProduct(Product p) {
		try {
			this.productDao.delProduct(p);
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		}
		return true;
	}
	
	/**
	 * 带条件按分页查询
	 * @param page
	 * @param product
	 * @return
	 */
	public Page findProduct4Page(Page page, Product product) {
		return this.productDao.findProduct4Page(page, product);
	}
	

}
